@section('beforeStyle')
{{ HTML::style('css/datatables/dataTables.bootstrap.css') }}
@show    

@section('title') @parent 订单管理 @stop
@section('page_title')@parent
订单管理
@show
@section('breadcrumb')@parent
{{ Breadcrumbs::render('order-index') }}
@show
@section('content')
<div class="row">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-header">
                <h3 class="box-title">订单列表</h3>
            </div>
            <div class="row">
                <div style="padding:0 2em;">
                    <div class="dataTables_filter" id="example1_filter">
                        <form id="orderSearchForm" method="get" action="{{ route('admin.order.index') }}">
                        <select class="control" name="search_type"><option value="order_no">订单号</option><option value="address.telephone" @if($search_type=='address.telephone') selected @endif>手机号</option></select>
                        <input type="text" aria-controls="example1" name="search_word" placeholder="订单号/手机号" value="{{ $word }}">
                        <input type="submit" value="搜索">
                        <div id="search_cols"></div>
                        </form>
                    </div>
                </div>
            </div>
            <div class="box-body table-responsive">
                <table id="example2" class="table table-bordered table-hover">
                    <thead>
                        <tr>
                            <th>订单号</th>
                            <th class="@if ( isset($qsort['user_id'])) sorting_{{ $qsort['user_id'] }} @else sorting @endif" name="sort[user_id]" >买家</th>
                            <th>手机号</th>
                            <th class="@if ( isset($qsort['price'])) sorting_{{ $qsort['price'] }} @else sorting @endif" name="sort[price]" >价格</th>
                            <th class="@if ( isset($qsort['created_at'])) sorting_{{ $qsort['created_at'] }} @else sorting @endif" name="sort[created_at]">下单时间</th>
                            <th>
                                <select class="filting" name="filter[state]">
                                    <option value="ALL">状态</option>
                                    @foreach ($works as $work)
                                        <option value="{{ $work->get_order_state() }}" @if( isset($qfilter['state']) && $qfilter['state']== $work->get_order_state()) selected @endif >{{ $work->name }}</option>
                                    @endforeach
                                </select>
                            </th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                    @foreach ( $orders as $row )
                        <tr>
                            <td>{{ $row->order_no }}</td>
                            <td>{{ $row->user->realname() }}</td>
                            <td>{{ $row->user->phone }}</td>
                            <td>{{ $row->price }}</td>
                            <td>{{ $row->created_at }}</td>
                            <td>{{ $row->workflow()->node->display_name }}</td>
                            <td>
                           @foreach ($works as $work)
                               @if ( $work->act_order > $row->workflow()->node->act_order  )
                                   <a href="{{ route('admin.order.update',['id'=>$row->id, 'step'=>$work->id])}}" class="btn btn-default">{{ $work->name }}</a>
                               @endif
                           @endforeach
                            </td>                            
                        </tr>
                     @endforeach  
                    </tbody>
                    
                </table>
            </div><!-- /.box-body -->
            <div class="box-footer clearfix">
		{{ $orders->appends(Input::except('page'))->links() }}
            </div>
        </div><!-- /.box -->
    </div>
</div>
@stop

@section('script')
    @parent
{{ HTML::script('js/plugins/datatables/jquery.dataTables.js') }}
{{ HTML::script('js/plugins/datatables/dataTables.bootstrap.js') }}
<script type="text/javascript">
$(document).ready(function() {
    $('#example2').dataTable({
        "bPaginate": false,
        "bLengthChange": false,
        "bFilter": false,
        "bSort": false,
        "bInfo": false,
        "bAutoWidth": false
    });
    $('th.sorting, th.sorting_asc, th.sorting_desc').click(function(){
        var order = 'asc';
        if ($(this).hasClass('sorting_asc')) {
            order = 'desc';
        }
        var nam = $(this).attr('name');
        var wrap = $('#search_cols');
        if ( wrap.find('input[name="'+nam+'"]').size() ) {
            wrap.find('input[name="'+nam+'"]').val( order );
        }else{
            wrap.append('<input type="hidden" name="'+nam+'" value="'+order+'">');
        }
        $('#orderSearchForm').submit();
    });
    $('select.filting').change(function(){
        var nam = $(this).attr('name');
        var val = $(this).val();
        var wrap = $('#search_cols');
        if ( wrap.find('input[name="'+nam+'"]').size() ) {
            wrap.find('input[name="'+nam+'"]').val( val );
        }else{
            wrap.append('<input type="hidden" name="'+nam+'" value="'+val+'">');
        }
        $('#orderSearchForm').submit();
    });
});
</script>
@stop